/**
*
* 2007-11-4 上午09:11:04
* @author xuhuan
*/

package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnEndIterationNode;

public class EndIterationNodeLoader extends NodeLoader {
	
	public List<Shape> loadNodes(Element root) {
		
		NodeList endIterationNodes = root.getElementsByTagName(SaturnEndIterationNode.KEY_NODE_ENDITERATION);
		
		List<Shape> shapes = new ArrayList<Shape>(endIterationNodes.getLength());
		
		for (int i = 0; i < endIterationNodes.getLength(); ++i) {
			SaturnEndIterationNode endStartIterationNode = new SaturnEndIterationNode();
			Node enditerationNode = endIterationNodes.item(i);
			String shapeId = super.getNodeAttributeValue(enditerationNode, Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(enditerationNode, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			String name = super.getNodeElementValue(enditerationNode, SaturnEndIterationNode.SHOW_ENDITERATION_NODE_NAME);
			String description = super.getNodeElementValue(enditerationNode, SaturnEndIterationNode.SHOW_ENDITERATION_NODE_DESCRITPION);
			String startid=super.getNodeElementValue(enditerationNode, SaturnEndIterationNode.SHOW_ENDITERATION_NODE_START_ID);
			
			Point location = super.getLocation(enditerationNode);
			Dimension size = new Dimension(50, 70);
			
			endStartIterationNode.setNode(enditerationNode);
			endStartIterationNode.setId(shapeId);
			endStartIterationNode.setLocation(location);
			endStartIterationNode.setName(name);
			endStartIterationNode.setNextId(nextId);
			endStartIterationNode.setDescription(description);
			endStartIterationNode.setSize(size);
			endStartIterationNode.setStartid(startid);
			
			shapes.add(endStartIterationNode);
		}
		
		return shapes;
	}
}
